package com.zifan.sever.controller;


import com.zifan.sever.bean.Admin;
import com.zifan.sever.bean.Role;
import com.zifan.sever.service.IAdminService;
import com.zifan.sever.service.IRoleService;
import com.zifan.sever.utils.RespBean;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zifan
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/system/admin")
public class AdminController {
    @Autowired
    private IAdminService adminService;

    @Autowired
    private IRoleService roleService;

    @ApiOperation(value = "获取所有操作员")
    @GetMapping("/")
    public List<Admin> getAllAdmins(String key){
        return adminService.getAllAdmins(key);
    }

    @ApiOperation(value = "更新操作员信息")
    @PutMapping("/")
    public RespBean updateAdmins(@RequestBody Admin admin){
        return adminService.updateAdmins(admin);
    }

    @ApiOperation(value = "删除操作员")
    @DeleteMapping("/{id}")
    public RespBean deleteAdmins(@PathVariable("id") Integer id){
        return adminService.deleteAdmins(id);
    }

    @ApiOperation(value = "获取所有的角色")
    @GetMapping("/roles")
    public List<Role> getAllRoles(){
        return roleService.list();
    }

    @ApiOperation(value = "更新操作员的角色列表")
    @PutMapping("/role")
    public RespBean updateAdminRoles(Integer adminId,Integer [] rids){
        return adminService.updateAdminRoles(adminId,rids);
    }
}
